package bz.ziro.kanbe.controller.mng.list;

import java.util.Date;
import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import bz.ziro.kanbe.model.SiteList;
import bz.ziro.kanbe.util.KeyFactory;

/**
 * リストの追加
 * @author Administrator
 */
public class AddController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(AddController.class.getName());

    @Override
    public Navigation run() {

        SiteList siteList = new SiteList();
        BeanUtil.copy(request, siteList);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        //作成日を設定
        siteList.setCreateDate(new Date());
        siteList.setCreator(user);
        
        //キーの作成
        Key key = KeyFactory.allocateListKey();
        siteList.setKey(key);
        //リストを登録
        Datastore.put(siteList);

        return null;
    }
}
